### Ensemble Averaging and Merging

## Task 1 Prediction 1 & 2: Averaging between 4 sets of world prediction + 1 set of Africa prediction ####

## s-2
Pred.1.Oct.2020 <- Pred.Ensemble.Task1.s2.africa[,c(1:2, 7:12)]
Pred.1.Oct.2020$month_id + 2 -> Pred.1.Oct.2020$month_id
Pred.1.Oct.2020$country_name <- Pred.Ensemble.Task1.s3.africa[1:54, 5]

Pred.1.Oct.2020$True.pred.1 <- rowMeans(Pred.1.Oct.2020[,c(1:4, 8)])

## experimental merging test - weighting UNITED forecasts double
Pred.1.Oct.2020$True.pred.2 <- rowMeans(Pred.1.Oct.2020[,c(1,2,3,3,4,4,8)])

MSE(Pred.1.Oct.2020$True.pred.1, Pred.1.Oct.2020$RF.GED.t1.s2.africa)
MSE(Pred.1.Oct.2020$True.pred.1, Pred.1.Oct.2020$RF.United.t1.s2)

## s-3
Pred.1.Nov.2020 <- Pred.Ensemble.Task1.s3.africa[55:108,]

Pred.1.Nov.2020$True.pred.1 <- rowMeans(Pred.1.Nov.2020[,c(1:2, 6:7, 9)])
Pred.1.Nov.2020$True.pred.2 <- rowMeans(Pred.1.Nov.2020[,c(1,2,6,6,7,7,9)])


MSE(Pred.1.Nov.2020$True.pred.1, Pred.1.Nov.2020$RF.GED.t1.s3.africa)
MSE(Pred.1.Nov.2020$True.pred.1, Pred.1.Nov.2020$RF.United.t1.s3)

## s-4
Pred.1.Dec.2020 <- Pred.Ensemble.Task1.s4.africa[109:162,]

Pred.1.Dec.2020$True.pred.1 <- rowMeans(Pred.1.Dec.2020[,c(1:2, 6:7, 9)])
Pred.1.Dec.2020$True.pred.2 <- rowMeans(Pred.1.Dec.2020[,c(1,2,6,6,7,7,9)])


MSE(Pred.1.Dec.2020$True.pred.1, Pred.1.Dec.2020$RF.GED.t1.s4.africa)
MSE(Pred.1.Dec.2020$True.pred.1, Pred.1.Dec.2020$RF.United.t1.s4)

## s-5
rm(Pred.1.Jan.2020) # oops
Pred.1.Jan.2021 <- Pred.Ensemble.Task1.s5.africa[163:216,]

Pred.1.Jan.2021$True.pred.1 <- rowMeans(Pred.1.Jan.2021[,c(1:2, 6:7, 9)])
Pred.1.Jan.2021$True.pred.2 <- rowMeans(Pred.1.Jan.2021[,c(1,2,6,6,7,7,9)])


MSE(Pred.1.Jan.2021$True.pred.1, Pred.1.Jan.2021$RF.GED.t1.s5.africa)
MSE(Pred.1.Jan.2021$True.pred.1, Pred.1.Jan.2021$RF.United.t1.s5)

## s-6
Pred.1.Feb.2021 <- Pred.Ensemble.Task1.s6.africa[217:270,]

Pred.1.Feb.2021$True.pred.1 <- rowMeans(Pred.1.Feb.2021[,c(1:2, 6:7, 9)])
Pred.1.Feb.2021$True.pred.2 <- rowMeans(Pred.1.Feb.2021[,c(1,2,6,6,7,7,9)])



MSE(Pred.1.Feb.2021$True.pred.1, Pred.1.Feb.2021$RF.GED.t1.s6.africa)
MSE(Pred.1.Feb.2021$True.pred.1, Pred.1.Feb.2021$RF.United.t1.s6)

## s-7
Pred.1.March.2021 <- Pred.Ensemble.Task1.s7.africa[271:324,]

Pred.1.March.2021$True.pred.1 <- rowMeans(Pred.1.March.2021[,c(1:2, 6:7, 9)])
Pred.1.March.2021$True.pred.2 <- rowMeans(Pred.1.March.2021[,c(1,2,6,6,7,7,9)])


MSE(Pred.1.March.2021$True.pred.1, Pred.1.March.2021$RF.GED.t1.s7.africa)
MSE(Pred.1.March.2021$True.pred.1, Pred.1.March.2021$RF.United.t1.s7)


### Complete Forecast Prediction 1

Prediction1.Oct2020.to.Mar2021.Ettensperger <-  Pred.1.Oct.2020[,c(5,6,7,9,10)]
Prediction1.Oct2020.to.Mar2021.Ettensperger[55:108,] <-  Pred.1.Nov.2020[,c(3,4,8,5,10)]
Prediction1.Oct2020.to.Mar2021.Ettensperger[109:162,] <-  Pred.1.Dec.2020[,c(3,4,8,5,10)]
Prediction1.Oct2020.to.Mar2021.Ettensperger[163:216,] <-  Pred.1.Jan.2021[,c(3,4,8,5,10)]
Prediction1.Oct2020.to.Mar2021.Ettensperger[217:270,] <-  Pred.1.Feb.2021[,c(3,4,8,5,10)]
Prediction1.Oct2020.to.Mar2021.Ettensperger[271:324,] <-  Pred.1.March.2021[,c(3,4,8,5,10)]

write.csv(Prediction1.Oct2020.to.Mar2021.Ettensperger, 
          file="Predicton1_Oct2020_to_Mar2021_Ettensperger.csv", row.names=FALSE)

Prediction2.Oct2020.to.Mar2021.Ettensperger <-  Pred.1.Oct.2020[,c(5,6,7,9,11)]
Prediction2.Oct2020.to.Mar2021.Ettensperger[55:108,] <-  Pred.1.Nov.2020[,c(3,4,8,5,11)]
Prediction2.Oct2020.to.Mar2021.Ettensperger[109:162,] <-  Pred.1.Dec.2020[,c(3,4,8,5,11)]
Prediction2.Oct2020.to.Mar2021.Ettensperger[163:216,] <-  Pred.1.Jan.2021[,c(3,4,8,5,11)]
Prediction2.Oct2020.to.Mar2021.Ettensperger[217:270,] <-  Pred.1.Feb.2021[,c(3,4,8,5,11)]
Prediction2.Oct2020.to.Mar2021.Ettensperger[271:324,] <-  Pred.1.March.2021[,c(3,4,8,5,11)]

write.csv(Prediction2.Oct2020.to.Mar2021.Ettensperger, 
          file="Predicton2_Oct2020_to_Mar2021_Ettensperger.csv", row.names=FALSE)


### Task 1 Prediction 2 : Double weights to Unified Data #####
## test
## s-2
Pred.2.Oct.2020 <- Pred.Ensemble.Task1.s2.africa[,c(1:2, 7:12)]
Pred.2.Oct.2020$month_id + 2 -> Pred.2.Oct.2020$month_id
Pred.2.Oct.2020$country_name <- Pred.Ensemble.Task1.s3.africa[1:54, 5]

Pred.2.Oct.2020$True.pred.2 <- rowMeans(Pred.2.Oct.2020[,c(1,2,3,3,4,4,8)])






## Task 2 Prediction 1 & 2 ####

## S-1
Pred.Ensemble.Task2.s1.africa <- read.csv("Pred_Ensemble_Task2_s1_africa.csv", header=TRUE)

Pred.Ensemble.Task2.s1.africa$Ensemble.forecast.t2.s1 <- rowMeans(Pred.Ensemble.Task2.s1.africa[,c(1:4, 9:10)])
Pred.Ensemble.Task2.s1.africa$Ensemble.forecast.t2.s1.p2 <- rowMeans(Pred.Ensemble.Task2.s1.africa[,c(1:4, 9:10, 13:14)])

MSE(Pred.Ensemble.Task2.s1.africa$Ensemble.forecast.t2.s1, Pred.Ensemble.Task2.s1.africa$real)
MSE(Pred.Ensemble.Task2.s1.africa$Ensemble.forecast.t2.s1.p2, Pred.Ensemble.Task2.s1.africa$real)

MSE(Pred.Ensemble.Task2.s1.africa$RF.GED.t2.s1, Pred.Ensemble.Task2.s1.africa$real)
MSE(Pred.Ensemble.Task2.s1.africa$RF.United.t2.s1, Pred.Ensemble.Task2.s1.africa$real)

write.csv(Pred.Ensemble.Task2.s1.africa, file="Pred_Ensemble_Task2_s1_africa.csv", row.names=FALSE)

## experiment (minimal benefit - expand in the future)
Pred.Ensemble.Task2.s1.africa$Ensemble.forecast.t2.s1 -> Pred.Ensemble.Task2.s1.africa$Ensemble.forecast.t2.s1.test
Pred.Ensemble.Task2.s1.africa$Ensemble.forecast.t2.s1.test[Pred.Ensemble.Task2.s1.africa$RF.United.t2.s1 == 0 | 
                                                           Pred.Ensemble.Task2.s1.africa$RF.United.t2.s1.africa == 0] <- 0
                                                           

MSE(Pred.Ensemble.Task2.s1.africa$Ensemble.forecast.t2.s1.test, Pred.Ensemble.Task2.s1.africa$real)                                 



## s-2
Pred.Ensemble.Task2.s2.africa <- read.csv("Pred_Ensemble_Task2_s2_africa.csv", header=TRUE)

Pred.Ensemble.Task2.s2.africa$Ensemble.forecast.t2.s2.p1 <- rowMeans(Pred.Ensemble.Task2.s2.africa[,c(1:4, 9:10)])
Pred.Ensemble.Task2.s2.africa$Ensemble.forecast.t2.s2.p2 <- rowMeans(Pred.Ensemble.Task2.s2.africa[,c(1:4, 9:10, 12:13)])

MSE(Pred.Ensemble.Task2.s2.africa$Ensemble.forecast.t2.s2.p1, Pred.Ensemble.Task2.s2.africa$real)
MSE(Pred.Ensemble.Task2.s2.africa$Ensemble.forecast.t2.s2.p2, Pred.Ensemble.Task2.s2.africa$real)

MSE(Pred.Ensemble.Task2.s2.africa$RF.GED.t2.s2, Pred.Ensemble.Task2.s2.africa$real)
MSE(Pred.Ensemble.Task2.s2.africa$RF.United.t2.s2, Pred.Ensemble.Task2.s2.africa$real)


write.csv(Pred.Ensemble.Task2.s2.africa, file="Pred_Ensemble_Task2_s2_africa.csv", row.names=FALSE)

## s-3
Pred.Ensemble.Task2.s3.africa <- read.csv("Pred_Ensemble_Task2_s3_africa.csv", header=TRUE)

Pred.Ensemble.Task2.s3.africa$Ensemble.forecast.t2.s3.p1 <- rowMeans(Pred.Ensemble.Task2.s3.africa[,c(1:4, 9:10)])
Pred.Ensemble.Task2.s3.africa$Ensemble.forecast.t2.s3.p2 <- rowMeans(Pred.Ensemble.Task2.s3.africa[,c(1:4, 9:10, 12:13)])

MSE(Pred.Ensemble.Task2.s3.africa$Ensemble.forecast.t2.s3.p1, Pred.Ensemble.Task2.s3.africa$real)
MSE(Pred.Ensemble.Task2.s3.africa$Ensemble.forecast.t2.s3.p2, Pred.Ensemble.Task2.s3.africa$real)

MSE(Pred.Ensemble.Task2.s3.africa$RF.GED.t2.s3, Pred.Ensemble.Task2.s3.africa$real)
MSE(Pred.Ensemble.Task2.s3.africa$RF.United.t2.s3, Pred.Ensemble.Task2.s3.africa$real)


write.csv(Pred.Ensemble.Task2.s3.africa, file="Pred_Ensemble_Task2_s3_africa.csv", row.names=FALSE)


## s-4  ## critical error ## replace "real" first then search in forecasts
Pred.Ensemble.Task2.s4.africa <- read.csv("Pred_Ensemble_Task2_s4_africa.csv", header=TRUE)
Pred.Ensemble.Task2.s4.africa$real <- views.ged.pred.t2$ln_ged_best_sb_s4


Pred.Ensemble.Task2.s4.africa$Ensemble.forecast.t2.s4.p1 <- rowMeans(Pred.Ensemble.Task2.s4.africa[,c(1:4, 9:10)])
Pred.Ensemble.Task2.s4.africa$Ensemble.forecast.t2.s4.p2 <- rowMeans(Pred.Ensemble.Task2.s4.africa[,c(1:4, 9:10, 12:13)])

MSE(Pred.Ensemble.Task2.s4.africa$Ensemble.forecast.t2.s4.p1, Pred.Ensemble.Task2.s4.africa$real)
MSE(Pred.Ensemble.Task2.s4.africa$Ensemble.forecast.t2.s4.p2, Pred.Ensemble.Task2.s4.africa$real)

MSE(Pred.Ensemble.Task2.s4.africa$RF.GED.t2.s4, Pred.Ensemble.Task2.s4.africa$real)
MSE(Pred.Ensemble.Task2.s4.africa$RF.United.t2.s4, Pred.Ensemble.Task2.s4.africa$real)

write.csv(Pred.Ensemble.Task2.s4.africa, file="Pred_Ensemble_Task2_s4_africa.csv", row.names=FALSE)


## s-5
Pred.Ensemble.Task2.s5.africa <- read.csv("Pred_Ensemble_Task2_s5_africa.csv", header=TRUE)

Pred.Ensemble.Task2.s5.africa$Ensemble.forecast.t2.s5.p1 <- rowMeans(Pred.Ensemble.Task2.s5.africa[,c(1:4, 10:11)])
Pred.Ensemble.Task2.s5.africa$Ensemble.forecast.t2.s5.p2 <- rowMeans(Pred.Ensemble.Task2.s5.africa[,c(1:4, 10:13)])

MSE(Pred.Ensemble.Task2.s5.africa$Ensemble.forecast.t2.s5.p1, Pred.Ensemble.Task2.s5.africa$ln_ged_best_sb_s5)
MSE(Pred.Ensemble.Task2.s5.africa$Ensemble.forecast.t2.s5.p2, Pred.Ensemble.Task2.s5.africa$ln_ged_best_sb_s5)

MSE(Pred.Ensemble.Task2.s5.africa$RF.GED.t2.s5, Pred.Ensemble.Task2.s5.africa$ln_ged_best_sb_s5)
MSE(Pred.Ensemble.Task2.s5.africa$RF.United.t2.s5, Pred.Ensemble.Task2.s5.africa$ln_ged_best_sb_s5)


write.csv(Pred.Ensemble.Task2.s5.africa, file="Pred_Ensemble_Task2_s5_africa.csv", row.names=FALSE)


## s-6
Pred.Ensemble.Task2.s6.africa <- read.csv("Pred_Ensemble_Task2_s6_africa.csv", header=TRUE)

Pred.Ensemble.Task2.s6.africa$Ensemble.forecast.t2.s6.p1 <- rowMeans(Pred.Ensemble.Task2.s6.africa[,c(1:4, 10:11)])
Pred.Ensemble.Task2.s6.africa$Ensemble.forecast.t2.s6.p2 <- rowMeans(Pred.Ensemble.Task2.s6.africa[,c(1:4, 10:13)])

MSE(Pred.Ensemble.Task2.s6.africa$Ensemble.forecast.t2.s6.p1, Pred.Ensemble.Task2.s6.africa$ln_ged_best_sb_s6)
MSE(Pred.Ensemble.Task2.s6.africa$Ensemble.forecast.t2.s6.p2, Pred.Ensemble.Task2.s6.africa$ln_ged_best_sb_s6)

MSE(Pred.Ensemble.Task2.s6.africa$RF.GED.t2.s6, Pred.Ensemble.Task2.s6.africa$ln_ged_best_sb_s6)
MSE(Pred.Ensemble.Task2.s6.africa$RF.United.t2.s6, Pred.Ensemble.Task2.s6.africa$ln_ged_best_sb_s6)


write.csv(Pred.Ensemble.Task2.s6.africa, file="Pred_Ensemble_Task2_s6_africa.csv", row.names=FALSE)


## s-7
Pred.Ensemble.Task2.s7.africa <- read.csv("Pred_Ensemble_Task2_s7_africa.csv", header=TRUE)

Pred.Ensemble.Task2.s7.africa$Ensemble.forecast.t2.s7.p1 <- rowMeans(Pred.Ensemble.Task2.s7.africa[,c(1:2, 6:7, 10:11)])


MSE(Pred.Ensemble.Task2.s7.africa$Ensemble.forecast.t2.s7.p1, Pred.Ensemble.Task2.s7.africa$ln_ged_best_sb_s7)
MSE(Pred.Ensemble.Task2.s7.africa$Ensemble.forecast.t2.s7.p2, Pred.Ensemble.Task2.s7.africa$ln_ged_best_sb_s7)

MSE(Pred.Ensemble.Task2.s7.africa$RF.GED.t2.s7, Pred.Ensemble.Task2.s7.africa$ln_ged_best_sb_s7)
MSE(Pred.Ensemble.Task2.s7.africa$RF.United.t2.s7, Pred.Ensemble.Task2.s7.africa$ln_ged_best_sb_s7)


write.csv(Pred.Ensemble.Task2.s7.africa, file="Pred_Ensemble_Task2_s7_africa.csv", row.names=FALSE)



Pred.Task2.Forecast1 <- read.csv("Ettensperger_Task2_Jan2017_to_Dec2019_Prediction_Ensemble.csv", header=TRUE)


Pred.Task2.Forecast1 <- Pred.Ensemble.Task2.s1.africa[,5:7]
Pred.Task2.Forecast1$S.1 <- Pred.Ensemble.Task2.s1.africa$Ensemble.forecast.t2.s1
Pred.Task2.Forecast1$S.2 <- Pred.Ensemble.Task2.s2.africa$Ensemble.forecast.t2.s2.p1
Pred.Task2.Forecast1$S.3 <- Pred.Ensemble.Task2.s3.africa$Ensemble.forecast.t2.s3.p1
Pred.Task2.Forecast1$S.4 <- Pred.Ensemble.Task2.s4.africa$Ensemble.forecast.t2.s4.p1
Pred.Task2.Forecast1$S.5 <- Pred.Ensemble.Task2.s5.africa$Ensemble.forecast.t2.s5.p1
Pred.Task2.Forecast1$S.6 <- Pred.Ensemble.Task2.s6.africa$Ensemble.forecast.t2.s6.p1
Pred.Task2.Forecast1$S.7 <- Pred.Ensemble.Task2.s7.africa$Ensemble.forecast.t2.s7.p1

write.csv(Pred.Task2.Forecast1, file="Ettensperger_Task2_Jan2017_to_Dec2019_Prediction_Ensemble.csv", row.names=FALSE)

######

## Task 3 Prediction 1 ####

## S-1
Pred.Ensemble.Task3.s1.africa <- read.csv("Pred_Ensemble_Task3_s1_africa.csv", header=TRUE)

Pred.Ensemble.Task3.s1.africa$Ensemble.forecast.t3.s1.p1 <- rowMeans(Pred.Ensemble.Task3.s1.africa[,c(1:2, 6:7, 9:10)])

write.csv(Pred.Ensemble.Task3.s1.africa, file="Pred_Ensemble_Task3_s1_africa.csv", row.names=FALSE)


## S-2
Pred.Ensemble.Task3.s2.africa <- read.csv("Pred_Ensemble_Task3_s2_africa.csv", header=TRUE)

Pred.Ensemble.Task3.s2.africa$Ensemble.forecast.t3.s2.p1 <- rowMeans(Pred.Ensemble.Task3.s2.africa[,c(1:2, 6:7, 9:10)])

write.csv(Pred.Ensemble.Task3.s2.africa, file="Pred_Ensemble_Task3_s2_africa.csv", row.names=FALSE)


## S-3
Pred.Ensemble.Task3.s3.africa <- read.csv("Pred_Ensemble_Task3_s3_africa.csv", header=TRUE)

Pred.Ensemble.Task3.s3.africa$Ensemble.forecast.t3.s3.p1 <- rowMeans(Pred.Ensemble.Task3.s3.africa[,c(1:2, 6:7, 9:10)])

write.csv(Pred.Ensemble.Task3.s3.africa, file="Pred_Ensemble_Task3_s3_africa.csv", row.names=FALSE)


## S-4
Pred.Ensemble.Task3.s4.africa <- read.csv("Pred_Ensemble_Task3_s4_africa.csv", header=TRUE)

Pred.Ensemble.Task3.s4.africa$Ensemble.forecast.t3.s4.p1 <- rowMeans(Pred.Ensemble.Task3.s4.africa[,c(1:2, 6:7, 9:10)])

write.csv(Pred.Ensemble.Task3.s4.africa, file="Pred_Ensemble_Task3_s4_africa.csv", row.names=FALSE)


## S-5
Pred.Ensemble.Task3.s5.africa <- read.csv("Pred_Ensemble_Task3_s5_africa.csv", header=TRUE)

Pred.Ensemble.Task3.s5.africa$Ensemble.forecast.t3.s5.p1 <- rowMeans(Pred.Ensemble.Task3.s5.africa[,c(1:2, 6:7, 9:10)])

write.csv(Pred.Ensemble.Task3.s5.africa, file="Pred_Ensemble_Task3_s5_africa.csv", row.names=FALSE)


## S-6
Pred.Ensemble.Task3.s6.africa <- read.csv("Pred_Ensemble_Task3_s6_africa.csv", header=TRUE)

Pred.Ensemble.Task3.s6.africa$Ensemble.forecast.t3.s6.p1 <- rowMeans(Pred.Ensemble.Task3.s6.africa[,c(1:2, 6:7, 9:10)])

write.csv(Pred.Ensemble.Task3.s6.africa, file="Pred_Ensemble_Task3_s6_africa.csv", row.names=FALSE)


## S-7
Pred.Ensemble.Task3.s7.africa <- read.csv("Pred_Ensemble_Task3_s7_africa.csv", header=TRUE)

Pred.Ensemble.Task3.s7.africa$Ensemble.forecast.t3.s7.p1 <- rowMeans(Pred.Ensemble.Task3.s7.africa[,c(1:2, 6:7, 9:10)])

write.csv(Pred.Ensemble.Task3.s7.africa, file="Pred_Ensemble_Task3_s7_africa.csv", row.names=FALSE)




Pred.Task3.Forecast1 <- read.csv("Ettensperger_Task3_Jan2014_to_Dec2016_Prediction_Ensemble.csv", header=TRUE)

Pred.Task3.Forecast1 <- Pred.Ensemble.Task3.s1.africa[,3:5]
Pred.Task3.Forecast1$S.1 <- Pred.Ensemble.Task3.s1.africa$Ensemble.forecast.t3.s1.p1
Pred.Task3.Forecast1$S.2 <- Pred.Ensemble.Task3.s2.africa$Ensemble.forecast.t3.s2.p1
Pred.Task3.Forecast1$S.3 <- Pred.Ensemble.Task3.s3.africa$Ensemble.forecast.t3.s3.p1
Pred.Task3.Forecast1$S.4 <- Pred.Ensemble.Task3.s4.africa$Ensemble.forecast.t3.s4.p1
Pred.Task3.Forecast1$S.5 <- Pred.Ensemble.Task3.s5.africa$Ensemble.forecast.t3.s5.p1
Pred.Task3.Forecast1$S.6 <- Pred.Ensemble.Task3.s6.africa$Ensemble.forecast.t3.s6.p1
Pred.Task3.Forecast1$S.7 <- Pred.Ensemble.Task3.s7.africa$Ensemble.forecast.t3.s7.p1

write.csv(Pred.Task3.Forecast1, file="Ettensperger_Task3_Jan2014_to_Dec2016_Prediction_Ensemble.csv", row.names=FALSE)





##############################
## Nice summary of views GED

views.ged <- read.csv("views_ged.csv", header=TRUE)
views.united <- read.csv("united_01.csv", header=TRUE)
psych::describeBy(views.ged)
views.ged.OUT <- psych::describeBy(views.ged[,1:48])
views.ged.OUT2 <- psych::describeBy(views.united[,1:92])

sjPlot::tab_df(views.ged.OUT)
sjPlot::tab_df(views.ged.OUT2)


## feature importance for report
feature.ged <- read.csv("importance_task2_s3_ged.csv", header=TRUE)
feature.uni <- read.csv("importance_task2_s1_united.csv", header=TRUE)

sjPlot::tab_df(feature.ged, digits=4)
sjPlot::tab_df(feature.uni[1:15,], digits=4)









################################
## tests - and abandoned experiments
0.5*log(27)

## Prediction 3 test : Averaging over all predictions

Pred.Oct.2020 <- Pred.Ensemble.Task1.s2[,c(1:2, 7:8)]

Pred.Oct.2020[,5:11] <- Pred.Ensemble.Task1.s3[1:195, 1:7]
Pred.Oct.2020[,c(7,8,9, 1:6, 10,11)] -> Pred.Oct.2020

Pred.Oct.2020[,12:15] <- Pred.Ensemble.Task1.s4[1:195, c(1:2,6:7)]
Pred.Oct.2020[,16:19] <- Pred.Ensemble.Task1.s5[1:195, c(1:2,6:7)]
Pred.Oct.2020[,20:23] <- Pred.Ensemble.Task1.s6[1:195, c(1:2,6:7)]
Pred.Oct.2020[,24:27] <- Pred.Ensemble.Task1.s7[1:195, c(1:2,6:7)]


Pred.Oct.2020$predictor.average <- rowMeans(Pred.Oct.2020[,4:27])
Pred.Oct.2020$predictor.average2 <- rowMeans(Pred.Oct.2020[,4:27])*2

RF.pred.compare2$predictor.average -> RF.pred.compare2$final.prediction
RF.pred.compare2$final.prediction[RF.pred.compare2$s1001 == 0 | 
                                    RF.pred.compare2$s1002 == 0 | 
                                    RF.pred.compare2$s1003 == 0 |
                                    RF.pred.compare2$acled1001 == 0 |
                                    RF.pred.compare2$acled1002 == 0 |
                                    RF.pred.compare2$acled1003 == 0 |
                                    RF.pred.compare2$ces1001 == 0 |
                                    RF.pred.compare2$ces1002 == 0 |
                                    RF.pred.compare2$ces1003 == 0 ] <- 0

write.csv(Pred.Oct.2020, file="Predictor_Oct_2020.csv", row.names=FALSE)